package com.cyf.filmDownload.film.entity;

import com.cyf.filmDownload.common.util.CollUtil;
import lombok.Data;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;


@Data
public class SearchResult {
    private String filmName;
    private String filmDesc;
    // 页面地址
    private String pageUrl;
    private String actor;
    // 1:电影  2：电视剧
    private Integer type;
    private Integer filmCount;
    private List<FilmDetail> filmDetails;

    public void setFilmDetails(List<FilmDetail> filmDetails) {
        this.filmDetails = filmDetails;
        if (CollUtil.isEmpty(filmDetails)) {
            return;
        }
        Set<Integer> list = filmDetails.stream().map(FilmDetail::getFilmIndex).collect(Collectors.toSet());
        type = list.size() == 1 ? 1 : 2;
        filmCount = list.size();
    }

    public void printFilmDetail() {
        if (filmCount == 1) {
            for (int i = 0; i < filmDetails.size(); i++) {
                System.out.println("播放地址: " + filmDetails.get(i).getFileViewUrl());
            }
        } else {
            for (int i = 0; i < filmDetails.size(); i++) {
                System.out.println("第" + filmDetails.get(i).getFilmIndex() + "集观看地址: " + filmDetails.get(i).getFileViewUrl());
            }
        }
    }
}